package action;

import model.ApiResultModel;
import http.Response;
import http.ResponseBuilder;
import service.UserService;

import java.util.Map;

public class UserAction {

    public ResponseBuilder responseBuilder = new ResponseBuilder();

    //JWT鉴权
    public Response login(Map<String, String> params) {
        String account = params.getOrDefault("account", "");
        String pwd = params.getOrDefault("pwd", "");
        ApiResultModel apiResultModel = UserService.login(account, pwd);
        return responseBuilder.buildResponseWithJsonBody(apiResultModel.json());
    }

    public Response register(Map<String, String> params) {
        String account = params.getOrDefault("account", "");
        String pwd = params.getOrDefault("pwd", "");
        ApiResultModel apiResultModel = UserService.register(account, pwd);
        return responseBuilder.buildResponseWithJsonBody(apiResultModel.json());
    }

    public Response query_user_name(Map<String, String> params) {
        long user_id = Long.valueOf(params.getOrDefault("user_id", "0"));
        long query_user = Long.valueOf(params.getOrDefault("query_user", "0"));
        ApiResultModel apiResultModel = UserService.queryUserName(query_user);
        return responseBuilder.buildResponseWithJsonBody(apiResultModel.json());
    }

}
